﻿
var flash_js_included = true;
if (typeof (Hjplayer_Nums) == "undefined") {
  Hjplayer_Nums = -1;
}
var Hjplayer_Nums = -1;

function GetFlash(id, playerfile, flashvers, width, height, NotTransparent) {
  if (playerfile.toLowerCase().indexOf("HjPlayer.swf") != -1) {
    NotTransparent = true;
  }
  if (NotTransparent == true) {
    NotTransparent = "window";
  } else {
    NotTransparent = "transparent";
  }
  var str = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0'";
  str += "width='" + width + "' height='" + height + "' id='" + id + "' align='middle' >";
  str += "<param name='allowScriptAccess' value='always' />";
  str += "<param name='movie' value='" + playerfile + "' />";
  str += "<param name='quality' value='high' />";
  str += "<param name='scale' value='showAll' />";
  str += "<param name='align' value='tl' />";
  str += "<param name='allowFullScreen' value='true' />";
  str += "<param name='wmode'  value='" + NotTransparent + "' />";
  str += "<param name='flashvars' value='" + flashvers + "' />";
  str += "<embed src='" + playerfile + "' quality='high' wmode='" + NotTransparent + "' scale='showAll' bgcolor='#ffffff' width='" + width + "' height='" + height + "' flashvars='" + flashvers + "' name='" + id + "' align='middle' allowFullScreen='true' allowScriptAccess='always' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer'/>";
  str += "</object>";
  document.write(str);
}

function GetFlashWords(id, playerfile, flashvers, width, height, NotTransparent) {
  if (NotTransparent == true) {
    NotTransparent = "window";
  } else {
    NotTransparent = "transparent";
  }
  var str = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,12,36'";
  str += "width='" + width + "' height='" + height + "' id='" + id + "' align='middle' >";
  str += "<param name='allowScriptAccess' value='always' />";
  str += "<param name='movie' value='" + playerfile + "' />";
  str += "<param name='quality' value='high' />";
  str += "<param name='scale' value='showall' />";
  str += "<param name='align' value='tl' />";
  str += "<param name='salign' value='tl' />";
  str += "<param name='allowFullScreen' value='true' />";
  str += "<param name='wmode' value='" + NotTransparent + "' />";
  str += "<param name='flashVars' value='" + flashvers + "' />";
  str += "<embed src='" + playerfile + "' quality='high' salign='tl' align='tl' scale='showAll' width='" + width + "' height='" + height + "' flashvars='" + flashvers + "' id='" + id + "' name='" + id + "' allowFullScreen='true' allowScriptAccess='always' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer'/>";
  str += "</object>";
  document.write(str);
}

function GetFlashCode(id, playerfile, flashvers, width, height, transparent) {
  if (playerfile.toLowerCase().indexOf("HjPlayer.swf") != -1) {
    NotTransparent = true;
  }
  if (transparent != true) {
    transparent = "window";
  } else {
    transparent = "transparent";
  }
  var str = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0'";
  str += "width='" + width + "' height='" + height + "' id='" + id + "' align='middle' >";
  str += "<param name='allowScriptAccess' value='always' />";
  str += "<param name='movie' value='" + playerfile + "' />";
  str += "<param name='quality' value='high' />";
  str += "<param name='scale' value='showAll' />";
  str += "<param name='allowFullScreen' value='true' />";
  str += "<param name='wmode' value='" + transparent + "' />";
  str += "<param name='flashvars' value='" + flashvers + "' />";
  str += "<param name='allowFullScreen' value='true' />";
  str += "<embed src='" + playerfile + "' quality='high' scale='showAll'  wmode='" + transparent + "' allowFullScreen='true' bgcolor='#ffffff' width='" + width + "' height='" + height + "' flashvars='" + flashvers + "' name='" + id + "' align='middle' allowScriptAccess='always' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />";
  str += "</object>";
  return str;
}
function GetWord(aWord) {
  var ID = 9999999 * Math.random();
  GetFlash("hjw_" + ID, "http://dict.hjenglish.com/flash/speaker.swf", "w=" + aWord.split(" ").join("#"), 30, 16, false);
}

//显示读音，暂时只支持中英
function ShowSound(aLinkObj, alan, aword) {
  if (alan == "en") {
    var sound = "https://d1.g.hjfile.cn/s/" + aword;
    aLinkObj.parentNode.innerHTML = GetFlashCode("dict_sound_" + aword, "http://dict.hjenglish.com/common/speaker_mini.swf", "autoplay=true&son=" + sound, 16, 16, true);
  }
  return false;
}

function GetHjPlayer(id, playerfile, flashvers, width, height) {
  var hjpid = Math.floor(Math.random() * 1000);
  Hjplayer_Nums++;
  if (Hjplayer_Nums > 0) {
    id = id + "_" + Hjplayer_Nums;
  }
  var str = "<div id='HjPlayer_div' name='HjPlayer_div' style='width:" + width + "px;height:" + height + "px;' valign='top'>";
  str += "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0'";
  str += "width='" + width + "' height='" + height + "' id='" + id + "' align='middle' valign='top' >";
  str += "<param name='allowScriptAccess' value='always' />";
  str += "<param name='movie' value='" + playerfile + "' />";
  str += "<param name='quality' value='high' />";
  str += "<param name='scale' value='showAll' />";
  str += "<param name='wmode' value='window' />";
  str += "<param name='bgcolor' value='#ffffff' />";
  str += "<param name='allowFullScreen' value='true' />";
  str += "<param name='flashvars' value='" + flashvers + "&hjpid=" + hjpid + "' />";
  str += "<embed src='" + playerfile + "' quality='high' scale='showAll' allowFullScreen='true' bgcolor='#ffffff' width='" + width + "' height='" + height + "' flashvars='" + flashvers + "' name='" + id + "' align='middle' allowScriptAccess='always' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer'/>";
  str += "</object>";
  str += "</div>";
  str += "<TABLE id='hjpcp_table" + hjpid + "' style='display:none;padding:0px,margin:0px' border='0' width='" + width + "' valign='top' cellspacing='0' cellpadding='0'>";
  str += "<TR>";
  str += "<TD>";
  str += "<div style='padding:0px;margin:0px;position:absolute;width:" + width + "px;border:0px;align=left' id='hjpcp_div" + hjpid + "' >";
  str += "</div>";
  str += "</TD>";
  str += "</TR>";
  str += "</TABLE>";
  document.write(str);
}
function ShiftMedia(targetmedia) {
  var oPlayer = document.getElementById("hjplayer");
  oPlayer.SetVariable("ShiftMedia", targetmedia);
  return false;
}

var soundPlayer = "/media/FlvPlayer.swf";
function ShowRecPlayer(aDiv, asoundFile) {
  if (IsIOSAgent()) {
    aDiv.parentNode.innerHTML = GetHtml5Player(true, asoundFile);
  }
  else {
    aDiv.parentNode.innerHTML = GetFlashCode("flv_" + Math.random(), soundPlayer, "with=263&height=27&autoplay=true&file=" + asoundFile, 200, 27, true);
  }
}


//var mp3Player = "/media/FlvPlayer.swf";
function ShowMp3Player(aDiv, asoundFile) {
  if (IsIOSAgent()) {
    aDiv.parentNode.innerHTML = GetHtml5Player(true, asoundFile);
  }
  else {
    aDiv.parentNode.innerHTML = GetFlashCode("mp3_" + Math.random(), soundPlayer, "with=263&height=27&autoplay=true&file=" + asoundFile, 200, 27, true);
  }
}

function GetHtml5Player(isAutoStart, theFile) {
    if (theFile.indexOf(".flv") > -1) {
        var flvFile = theFile;
        theFile = "https://a2.c.hjfile.cn/handler/flv2mp3.ashx?f=" + theFile + "&callback=?";
        $.ajax({
            url: theFile,
            async: false,
            dataType: "jsonp",
            success: function (data) {
            }
        })
        flvFile = flvFile.replace(/default/ig, "mp3");
        flvFile = flvFile.replace(/\.flv/ig, ".mp3");
        return createHtml5Player(isAutoStart, flvFile);
    }
    else {
        return createHtml5Player(true, theFile);
    }
}

function createHtml5Player(isAutoStart, theFile) {
  var htmlstr = "<audio style=\"width:263px;height:27px;\" src=\"" + theFile + "\" controls=\"controls\" ";
  if (isAutoStart) {
    htmlstr = htmlstr + " autoplay=\"autoplay\" ";
  }
  htmlstr = htmlstr + " ></audio>";
  return htmlstr;
}

function IsIOSAgent() {
  var keywords = ["iphone", "ipod", "ipad"];
  var agent = navigator.userAgent.toLowerCase();
  for (var i = 0; i < keywords.length; i++) {
    if (agent.indexOf(keywords[i]) > -1) {
      return true;
    }
  }
  return false;
}
